package models;

import java.util.*;

import javax.persistence.*;

import controllers.Application;

import play.Logger;
import play.data.validation.Required;
import play.db.jpa.*;

@Entity
public class Candidat extends Model {

	@ManyToOne
	public Agent agent;
	@ManyToOne
	public Stage stage;

	public Agent getAgent() {
		return agent;
	}

	@ManyToOne
	public EtatCandid etatCandid;

	public boolean demandeAnnulation;
	
	public boolean logement;

	@Required
	public String motivation;

	public String precisionDate;

	public String motifRefus;

	@ManyToOne
	public MotifAnnulation motifAnnulation;
	
	public boolean candidature_non_annuler;

	@Required
	@ManyToOne
	public Role role;

	@OneToMany
	public static List<Agent> respDepartemental=new ArrayList<Agent>();

	public Candidat(Agent agent, Stage stage, String motivation,Long role){
		this.agent = agent;
		this.stage = stage;
		this.motivation=motivation;
		this.role = Role.findById(role);
		etatCandid = (EtatCandid) EtatCandid.findAll().get(0);	
	}

	public void candidater(boolean logement, Long role, String precisionDate){
		this.agent.addCandidature(this);
		this.stage.addCandidature(this);
		Role roles = Role.findById(role);
		this.role.setNom(roles.getNom());
		this.logement=logement;
		this.precisionDate=precisionDate;	
	}

	public String getMotifRefus() {
		return motifRefus;
	}

	public void setMotifRefus(String motifRefus) {
		this.motifRefus = motifRefus;
	}

	public boolean equals(Candidat c){
		return c.agent.equals(this.agent)&&c.stage.equals(this.stage);

	}

	public String toString(){
		return agent.nom+" "+agent.prenom;
	}

	public void setAgent(Agent agent) {
		this.agent = agent;
	}

	public Stage getStage() {
		return stage;
	}

	public void setStage(Stage stage) {
		this.stage = stage;
	}

	public EtatCandid getEtatCandid() {
		return etatCandid;
	}

	public void setEtatCandid(EtatCandid etatCandid) {
		this.etatCandid = etatCandid;
	}

	public EtatCandid getMotifAnnulation() {
		return etatCandid;
	}

	public void setMotifAnnulation(MotifAnnulation motifAnnulation) {
		this.motifAnnulation = motifAnnulation;
	}


}
